package com.example.demo.level3.homework;


import com.example.demo.level3.LearnStream;
import com.example.demo.level3.pojo.People;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @description
* @author yyh
* @date 2020/11/11 21:13
*/
public class AnswerByYyh{
    /*
     * 思考题：
     * 请将list根据分数是否及格进行分组，并将分数从高到低排序，每个组保留前三名，获取他们的姓名+成绩的拼接，拼接符号为->
     * 注：不及格的人指score小于60，及格为true，不及格为false
     * 注2：打印的对象类型为 Map<Boolean, String>
     */
    private static final String PASS_SCORE = "60";

    @Test
    public void solution() {
        List<People> list = LearnStream.getList();
        // 请对list进行操作，获取answer
        Map<Boolean, String> answer = list.stream().collect(Collectors.groupingBy(
                people -> people.getScore().compareTo(new BigDecimal(PASS_SCORE)) >= 0,
                Collectors.collectingAndThen(Collectors.toList(),
                        peopleList -> peopleList.stream().sorted(Comparator.comparing(People::getScore,
                                Comparator.reverseOrder())).limit(3)
                                .map(x -> x.getName() + x.getScore()).collect(Collectors.joining("->"))
        )));
        System.out.println(answer);
    }
}